package com.yangkunhong.www.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ValidateUtil {
    /**
     * 手机号正则规则
     * @param mobile
     * @return
     */
    public static boolean isMobile(String mobile){
        Pattern pattern = Pattern.compile("^1(3\\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$");

        return pattern.matcher(mobile).matches();
        ///^\S*(?=\S{6,})(?=\S*\d)(?=\S*[A-Z])(?=\S*[a-z])(?=\S*[!@#$%^&*? ])\S*$/
    }

    /**
     * 邮箱格式正则验证
     * @param email
     * @return
     */
    public static boolean isEmail(String email){
        Pattern pattern = Pattern.compile("^[\\da-z]+([\\-\\.\\_]?[\\da-z]+)*@[\\da-z]+([\\-\\.]?[\\da-z]+)*(\\.[a-z]{2,})+$");
        return pattern.matcher(email).matches();
    }

    /**
     * 用户名正则：最长10字符，支持中文、英文
     * @param username
     * @return
     */
    public static boolean isUserName(String username){
        Pattern pattern = Pattern.compile("^([\\u4E00-\\uFA29]|[\\uE7C7-\\uE7F3]|[a-zA-Z]){1,10}$");
        return pattern.matcher(username).matches();
    }
}
